package br.com.hsp.system.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.hsp.organizacao.Cartao;



public class CartaoRepository {
	
	private EntityManager manager ;
	
	public CartaoRepository ( EntityManager manager ) {
		this.manager = manager ;
	}
	
	public void add(Cartao cartao) {
		this.manager.persist(cartao);
	}
	
	public void remove(String codigo_cartao) {
		Cartao cartao = this.procura(codigo_cartao);
		this.manager.remove(cartao);
	}
	
	public Cartao atualiza(Cartao cartao) {
		return this.manager.merge(cartao);
	}
	
	public Cartao procura(String codigo_cartao) {
		return this.manager.find(Cartao.class, codigo_cartao);
	}
	
	public List<Cartao> getLista() {
		Query query = this.manager.createQuery("SELECT x from Cartao x");
		return query.getResultList();
	}
}
